package com.qmx.qmxapp.fragment;


import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.widget.DividerItemDecoration;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;

import com.qmx.qmxapp.R;
import com.qmx.qmxapp.adapter.BaseRecyclerAdapter;
import com.qmx.qmxapp.adapter.BaseRecyclerHolder;
import com.qmx.qmxapp.base.BaseFragment;

import java.util.ArrayList;
import java.util.List;
import java.util.Locale;

/**
 * @author ChengXiangtong
 * @create 2018/11/20
 * @Describe 视频通话中最近联系人布局
 */
public class RecentCallFragment extends BaseFragment {
    private List<String> list;
    private RecyclerView recyclerView;
    private BaseRecyclerAdapter<String> adapter;
    private View mView;

    public RecentCallFragment() {
        // Required empty public constructor
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        mView = inflater.inflate(R.layout.fragment_recent_call, container, false);
        list = new ArrayList<>();

        initList();

        adapter = new BaseRecyclerAdapter<String>(getActivity(), list, R.layout.layout_meeting_item) {
            @Override
            public void convert(BaseRecyclerHolder holder, String item, int position, boolean isScrolling) {
                holder.setText(R.id.item_text_user_name, item.toString());
                //                if (item.getImageUrl() != null){
                //                    holder.setImageByUrl(R.id.item_image,item.getImageUrl());
                //                }else {
                //                    holder.setImageResource(R.id.item_image,item.getImageId());
                //                }
            }

        };
        adapter.setOnItemClickListener(new BaseRecyclerAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(RecyclerView parent, final View view, int position) {
                Toast.makeText(getActivity(), String.format(Locale.CHINA, "你点击了第%d项,长按会删除！", position), Toast.LENGTH_SHORT).show();
            }
        });

        adapter.setOnItemLongClickListener(new BaseRecyclerAdapter.OnItemLongClickListener() {
            @Override
            public boolean onItemLongClick(RecyclerView parent, View view, int position) {
                adapter.delete(position);
                return true;
            }
        });

        recyclerView = (RecyclerView) mView.findViewById(R.id.recyclerview);
        recyclerView.setLayoutManager(new LinearLayoutManager(getActivity(), LinearLayoutManager.VERTICAL, false));
        recyclerView.addItemDecoration(new DividerItemDecoration(getContext(), DividerItemDecoration.VERTICAL));
        recyclerView.setAdapter(adapter);

        return mView;

    }

    public void initList() {
        for (int i = 0; i < 55; i++) {
            list.add("测试" + i);
        }
        for (int i = 0; i < 5; i++) {
            //            list.add(new Data("网络 "+i,"http://pic.cnblogs.com/face/845964/20160301162812.png"));
        }
    }

}
